#include "Cercle.h"
#include <math.h>


Circle2::Circle2(const float x, const float y, const float radius)
{
	this->x = x;
	this->y = y;
	this->center.x = x;
	this->center.y = y;
	this->radius = radius;
}

Circle2::Circle2(const Vector2D& center, float radius)
{
	this->x = center.x;
	this->y = center.y;
	this->center = center;
	this->radius = radius;
}

// Calcul distance entre centre cercle et un point.
bool Circle2::Contains(float x, float y) const
{
	float length;
	float heigth;

	if (this->x > x)
		length = this->x - x;
	else
		length = x - this->x;
	
	if (this->x > y)
		heigth = this->x - y;
	else
		heigth = y - this->x;

	if (((length * length) + (heigth * heigth)) < (radius * radius))
		return true;
	else

		return false;
}

// Calcul distance entre centre cercle et un point.
bool Circle2::Contains(const Vector2D& point) const
{
	float length;
	float heigth;

	if (x > point.x)
		length = x - point.x;
	else
		length = point.x - x;
	
	if (y > point.y)
		heigth = y - point.y;
	else
		heigth = point.y - y;

	if (((length * length) + (heigth * heigth)) <= GetRadiusSq())
		return true;
	else
		return false;
}

float Circle2::GetX() const
{
	return x;
}

float Circle2::GetY() const
{
	return y;
}

float Circle2::GetRadiusSq() const
{
	return radius * radius;
}

float Circle2::GetRadius() const
{
	return radius;
}

void Circle2::SetPosition(const Vector2D& vect)
{
	this->x = vect.x;
	this->y = vect.y;
}

void Circle2::SetPosition(float x, float y)
{
	this->center.x = x;
	this->center.y = y;
}

void Circle2::MoveBy(const Vector2D& vect)
{
	this->x += vect.x;
	this->y += vect.y;
}

void Circle2::MoveBy(float x, float y)
{
	this->center.x += x;
	this->center.y += y;
}

bool Circle2::CollidesWith(const Circle2& circ) const
{
	Vector2D between = Vector2D::Substract(circ.GetCenter(), center);
	float lengthSq = Vector2D::LengthSq(between);
	float sumRadiusSq = circ.GetRadiusSq() + GetRadiusSq();
	return lengthSq <= sumRadiusSq;
}